/****************************************************************************/
/* obligatory global struct */
/****************************************************************************/
-xcsv_file_t xcsv_file;
+XcsvFile xcsv_file;
extern char* xcsv_urlbase;
extern char* prefer_shortnames;
/*****************************************************************************/
/* xcsv_file_init() - prepare xcsv_file for first use. */
/*****************************************************************************/
-void
-xcsv_file_init(void)
+void xcsv_file_init(void)
{
- memset(&xcsv_file, '\0', sizeof(xcsv_file_t));
+ xcsv_file.is_internal = false;
+ xcsv_file.prologue_lines = 0;
+ xcsv_file.epilogue_lines = 0;
+ xcsv_file.field_delimiter = QString();
+ xcsv_file.field_encloser = QString();
+ xcsv_file.record_delimiter = QString();
+ xcsv_file.badchars = NULL;
+ xcsv_file.ifield_ct = 0;
+ xcsv_file.ofield_ct = 0;
+ xcsv_file.xcsvfp = NULL;
+ xcsv_file.fname = QString();
+ xcsv_file.description = NULL;
+ xcsv_file.extension = NULL;
QUEUE_INIT(&xcsv_file.prologue);
QUEUE_INIT(&xcsv_file.epilogue);
xcsv_file.gps_datum = GPS_DATUM_WGS84;
}
+XcsvFile::XcsvFile() {
+ xcsv_file_init();
+}
+
void validate_fieldmap(field_map_t* fmp, bool is_output) {
QString qkey = fmp->key;
QString qval = fmp->val;
wpt_tmp = new Waypoint;
s = buff;
- s = csv_lineparse(s, xcsv_file.field_delimiter,
- xcsv_file.field_encloser, linecount);
+ s = csv_lineparse(s, CSTR(xcsv_file.field_delimiter),
+ CSTR(xcsv_file.field_encloser), linecount);
if (QUEUE_EMPTY(&xcsv_file.ifield)) {
fatal(MYNAME ": attempt to read, but style '%s' has no IFIELDs in it.\n", xcsv_file.description? xcsv_file.description : "unknown");
break;
}
- s = csv_lineparse(NULL, xcsv_file.field_delimiter,
- xcsv_file.field_encloser, linecount);
+ s = csv_lineparse(NULL, CSTR(xcsv_file.field_delimiter),
+ CSTR(xcsv_file.field_encloser), linecount);
}
if ((xcsv_file.gps_datum > -1) && (xcsv_file.gps_datum != GPS_DATUM_WGS84)) {
xcsv_waypt_pr(const Waypoint* wpt)
{
QString buff;
- const char* write_delimiter;
int i;
field_map_t* fmp;
queue* elem, *tmp;
longitude = oldlon = wpt->longitude;
latitude = oldlat = wpt->latitude;
- if (xcsv_file.field_delimiter && strcmp(xcsv_file.field_delimiter, "\\w") == 0) {
+ QString write_delimiter;
+ if (xcsv_file.field_delimiter == "\\w") {
write_delimiter = " ";
} else {
write_delimiter = xcsv_file.field_delimiter;
fmp = (field_map_t*) elem;
if ((i != 0) && !(fmp->options & OPTIONS_NODELIM)) {
- gbfprintf(xcsv_file.xcsvfp, write_delimiter);
+ gbfputs(write_delimiter, xcsv_file.xcsvfp);
}
if (fmp->options & OPTIONS_ABSOLUTE) {
continue;
}
- if (xcsv_file.field_encloser) {
+ if (!xcsv_file.field_encloser.isEmpty()) {
/* print the enclosing character(s) */
- gbfprintf(xcsv_file.xcsvfp, "%s", xcsv_file.field_encloser);
+ gbfputs(xcsv_file.record_delimiter, xcsv_file.xcsvfp);
}
/* As a special case (pronounced "horrible hack") we allow
}
gbfputs(obuff, xcsv_file.xcsvfp);
- if (xcsv_file.field_encloser) {
+ if (!xcsv_file.field_encloser.isEmpty()) {
/* print the enclosing character(s) */
- gbfprintf(xcsv_file.xcsvfp, "%s", xcsv_file.field_encloser);
+ gbfputs(xcsv_file.record_delimiter, xcsv_file.xcsvfp);
}
}
- gbfprintf(xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter);
+ gbfputs(xcsv_file.record_delimiter, xcsv_file.xcsvfp);
/* increment the index counter */
waypt_out_count++;
QString t = dt.toString("hh:mm:ss");
cout.replace("__TIME__", t);
}
- gbfprintf(xcsv_file.xcsvfp, "%s", CSTR(cout));
- gbfprintf(xcsv_file.xcsvfp, "%s", xcsv_file.record_delimiter);
+ gbfputs(cout, xcsv_file.xcsvfp);
+ gbfputs(xcsv_file.record_delimiter, xcsv_file.xcsvfp);
}
if ((xcsv_file.datatype == 0) || (xcsv_file.datatype == wptdata)) {
/* output epilogue lines, if any. */
QUEUE_FOR_EACH(&xcsv_file.epilogue, elem, tmp) {
ogp = (ogue_t*) elem;
- gbfprintf(xcsv_file.xcsvfp, "%s%s", ogp->val, xcsv_file.record_delimiter);
+ gbfputs(ogp->val, xcsv_file.xcsvfp);
+ gbfputs(xcsv_file.record_delimiter, xcsv_file.xcsvfp);
}
}
#endif
} char_map_t;
/*
- * a type describing all the wonderful elements of xcsv files, in a
+ * a Class describing all the wonderful elements of xcsv files, in a
* nutshell.
+ * It completely shows that this began life as a C struct...baby steps.
*/
-typedef struct {
- int is_internal; /* bool - is internal (1) or parsed (0) */
+class XcsvFile {
+ public:
+ XcsvFile();
+
+ bool is_internal; /* bool - is internal (1) or parsed (0) */
int prologue_lines; /* # of lines to ignore at top of the file */
int epilogue_lines; /* # of lines to ignore at bottom of file */
/* footer lines for writing at the bottom of the file. */
queue epilogue;
- char* field_delimiter; /* comma, quote, etc... */
- char* field_encloser; /* doublequote, etc... */
- char* record_delimiter; /* newline, c/r, etc... */
+ QString field_delimiter; /* comma, quote, etc... */
+ QString field_encloser; /* doublequote, etc... */
+ QString record_delimiter; /* newline, c/r, etc... */
- char* badchars; /* characters we never write to output */
+ char* badchars; /* characters we never write to output */
queue ifield; /* input field mapping */
queue* ofield; /* output field mapping */
int ofield_ct; /* actual # of ofields */
gbfile* xcsvfp; /* ptr to current *open* data file */
- char* fname; /* ptr to filename of above. */
+ QString fname; /* ptr to filename of above. */
char* description; /* Description for help text */
char* extension; /* preferred filename extension (for wrappers)*/
gpsdata_type datatype; /* can be wptdata, rtedata or trkdata */
/* ... or ZERO to keep the old behaviour */
-} xcsv_file_t;
+};
/****************************************************************************/
/* obligatory global struct */
/****************************************************************************/
-extern xcsv_file_t xcsv_file;
+extern XcsvFile xcsv_file;
}
/* other alloc'd glory */
- if (xcsv_file.field_delimiter) {
- xfree(xcsv_file.field_delimiter);
- }
-
- if (xcsv_file.field_encloser) {
- xfree(xcsv_file.field_encloser);
- }
-
- if (xcsv_file.record_delimiter) {
- xfree(xcsv_file.record_delimiter);
- }
+ xcsv_file.field_delimiter = QString();
+ xcsv_file.field_encloser = QString();
+ xcsv_file.record_delimiter = QString();
if (xcsv_file.badchars) {
xfree(xcsv_file.badchars);
/* return everything to zeros */
internal = xcsv_file.is_internal;
- memset(&xcsv_file, '\0', sizeof(xcsv_file));
xcsv_file.is_internal = internal;
}
xcsv_file.field_delimiter = sp;
}
- p = csv_stringtrim(xcsv_file.field_delimiter, " ", 0);
+ p = csv_stringtrim(CSTR(xcsv_file.field_delimiter), " ", 0);
/* field delimiters are always bad characters */
if (0 == strcmp(p, "\\w")) {
xcsv_file.field_encloser = sp;
}
- p = csv_stringtrim(xcsv_file.field_encloser, " ", 0);
+ p = csv_stringtrim(CSTR(xcsv_file.field_encloser), " ", 0);
/* field_enclosers are always bad characters */
if (xcsv_file.badchars) {
xcsv_file.record_delimiter = sp;
}
- p = csv_stringtrim(xcsv_file.record_delimiter, " ", 0);
+ p = csv_stringtrim(CSTR(xcsv_file.record_delimiter), " ", 0);
/* record delimiters are always bad characters */
if (xcsv_file.badchars) {